﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Diagnostics;

namespace DotNetMigrations
{
	public class Output
	{
		/// <summary>
		/// Output usage help for all commands.
		/// </summary>
		public static void HelpContent()
		{
			Console.Write(@"
DotNetMigrations v" + Program.GetAppVersion() + @"

Example usage:
--------------------------------
Generate a new migration:
    db generate my_migration_name

Check current schema version:
    db version MyConnectionStringName
    db version ""SERVER=.\SQLEXPRESS;DATABASE=Northwind;""

Migrate to the latest version:
    db migrate MyConnectionStringName

Migrate to a specific version:
    db migrate 24 MyConnectionStringName

Rollback/Migrate down to the previous version:
    db rollback MyConnectionStringName

Bulk load data into database tables:
    db bulkload MyConnectionStringName C:\MyDataToInsert.xml

You can use a specific connection string or reference
by name a connection string in the db.exe.config file.

");
		}

		/// <summary>
		/// Write a message to the console.
		/// </summary>
		public static void Write(string msg)
		{
			WriteToConsole(msg, ConsoleColor.DarkBlue, ConsoleColor.Gray);
		}

		/// <summary>
		/// Write a warning message to the console.
		/// </summary>
		public static void Warn(string msg)
		{
			WriteToConsole(msg, ConsoleColor.DarkRed, ConsoleColor.Gray);
		}

        /// <summary>
        /// Write a verbose message to the console.
        /// </summary>
        public static void WriteVerbose(string msg)
        {
            WriteToConsole(msg, ConsoleColor.Gray, Console.BackgroundColor);
        }

		/// <summary>
		/// Write a message to the console using the specified colors.
		/// </summary>
		private static void WriteToConsole(string msg, ConsoleColor foreColor, ConsoleColor backColor)
		{
			ConsoleColor origForeColor = Console.ForegroundColor;
			ConsoleColor origBackColor = Console.BackgroundColor;

			Console.ForegroundColor = foreColor;
			Console.BackgroundColor = backColor;
			Console.WriteLine(msg);

			Console.ForegroundColor = origForeColor;
			Console.BackgroundColor = origBackColor;
		}
	}
}
